package com.yinet.web.controller.tool.json;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.net.URL;

public class JsonResourceUtils {


    private JsonResourceUtils() {

    }
    //filename 为文件名字 如 “/json/app_version_info.json”
    public static String getJsonObjFromResource(String filename) {
        String content  = null;
        if (!filename.contains(".json")) {
            filename += ".json";
        }
        try {
            URL url = JsonResourceUtils.class.getResource(filename);
            String path = url.getPath();
            File file = new File(path);
            System.err.println(file.exists());
            if (file.exists()) {
                 content = FileUtils.readFileToString(file, "UTF-8");

            } else {
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return content.trim();
    }
}
